//
// Created by LONG on 2020/10/18.
//

#ifndef CSP_INCLUDE_UTILS_HASHTABLE_H_
#define CSP_INCLUDE_UTILS_HASHTABLE_H_

#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include "commDef.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct HashNodeKeyVal
{
    void *key;
    void *data;
} S_HashNodeKeyVal;

typedef struct HashNode S_HashNode;
typedef struct HashTable S_HashTable;

typedef struct HashTableIter
{
    S_HashTable *hashTable;
    S_HashNode  *nextEntry;
    uint32_t     nextIndex;
} S_HashTableIter;

typedef uint32_t (*HashTableHashFunc)(void* value);
typedef int32_t (*HashTableEqualFunc)(void* value1, void* value2);

S_HashTable* HashTable_Create(uint32_t size, HashTableHashFunc hashFunc, HashTableEqualFunc equalFunc);
void     HashTable_Destroy(S_HashTable *self);
int32_t  HashTable_Insert(S_HashTable *self, void *key, void *data);
S_HashNodeKeyVal* HashTable_Remove(S_HashTable *self, void *key);
S_HashNodeKeyVal* HashTable_Lookup(S_HashTable *self, void *key);
int32_t  HashTable_Resize(S_HashTable *self, uint32_t size);
uint32_t HashTable_Capacity(S_HashTable *self);
uint32_t HashTable_Count(S_HashTable *self);
void     HashTable_Iterate(S_HashTable *self, S_HashTableIter *iterator);
int32_t  HashTableIter_HasMore(S_HashTableIter *iterator);
S_HashNodeKeyVal* HashTableIter_Next(S_HashTableIter *iterator);

#ifdef __cplusplus
}
#endif

#endif //CSP_INCLUDE_UTILS_HASHTABLE_H_
